<template>
  <div class="video-center">
    <nav class="nav">
      <ul class="nav-list">
        <button @click="goToHome">首页</button>
        <li class="active">视频中心</li>
        <button @click="goToSubmit">创作中心</button>
        <button @click="goToCheck">审核中心</button>
        <button @click="goToAIChat">智能问答</button>
      </ul>
      <button class="user-icon">
        <img
          src="../assets/yonghu.png"
          style="width: 37px; height: 37px; position: absolute; top: 1px; left: 3px"
        />
      </button>
    </nav>

    <div class="recommend-list">
      <div class="recommend-item" v-for="(video, index) in videoList" :key="index">
        <img
          :src="video.coverImage"
          alt="Video Cover"
          class="item-video"
          style="width: 100%; height: 200px; object-fit: cover"
        />
        <h4>{{ video.title }}</h4>
        <div class="item-meta">
          <span>{{ video.author }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import axios from "../axios/index.js";
import { useRouter } from 'vue-router';

const router = useRouter();

const goToSubmit = () => {
  router.push({ name: 'submit' });
};

const goToCheck = () => {
  router.push({ name: 'checkCenter' });
};

const goToAIChat = () => {
  router.push({ name: 'AIchat' });
};

const goToHome = () => {
  router.push({ name: 'Home' });
};

const videoList = ref([]);

onMounted(async () => {
  try {
    const response = await axios.get("/video-list/approved");
    videoList.value = response.data;
  } catch (error) {
    console.error("Error fetching approved videos:", error);
  }
});
</script>

<style scoped>
/* 导航栏样式 */
.nav {
  display: flex;
  align-items: center;
  background: #f8f9fa;
  box-sizing: border-box;
  padding: 0 20px;
  height: 60px;
  border-bottom: 1px solid #e9ecef;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
  justify-content: center;
}
.nav-list {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  justify-content: space-around;
  width: 60%;
  max-width: 800px;
  align-items: center;
}
.nav-list button {
  padding: 10px 15px;
}
.nav-list li.active {
  cursor: pointer;
  color: #495057;
  color: white;
  background: #007bff;
  padding: 20px 15px;
  border-radius: 4px;
  font-weight: bold;
  width: 100px;
}
.user-icon {
  width: 45px;
  height: 45px;
  background: #dee2e6;
  border-radius: 50%;
  position: absolute;
  right: 50px;
}
.video-center {
  padding: 40px 20px;
}

.recommend-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}

.recommend-item {
  border: 1px solid #dee2e6;
  padding: 15px;
}

.item-video {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.item-meta {
  font-size: 12px;
  color: #6c757d;
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
}
</style>
